<div class="dis-Table" id="body-div">
	<div class="border-right" style="width:200px;background-color: #f5f5f5;">
		<div class="treeShowScroll">
			<div id="getAll" class="all-tree" style="cursor:pointer;">
				<i class="fa fa-list-ul" aria-hidden="true" ></i> <span></span>
			</div>
			<div class="search-jstree" >
				<input id="search-jstree-input" style="height: 25px;"/>
				<img class="middle fa fa-search"  src="static/img/search-input_wev8.png">
			</div>
			<div id="carKindjsTree" style="background-color: rgb(245,245,245)!important;"></div>
		</div>
	</div>
	<div class="layui-fluid">
		<div class="layui-card">
			<h5 class="rightTbTitle"><a id="titleBar" style="color:#696a6c;">左树右表演示</a></h5>
			<div class="layui-card-body">
				<form id="searchForm" class="searchForm form-inline">
					<input id="treeId" name="parent.id" type="hidden" value="" />
					<input id="treeName" type="hidden" value="" />
					<div class="searchDiv positionSpc">
						<div class="form-group pull-left important">
							<span>名称</span>
							<input name="s01" component-type="input" class="form-control" type="text" value="" maxlength="64" />
						</div>
					</div>
				</form>
				<div id="toolbar" class="toolbar">
					<div class="pull-right">
						<a id="searchBtn" class="btn btn-success btn-bordered btn-sm"><i class="fa fa-search"></i> <font>查询</font></a>
						<a id="resetBtn" class="btn btn-success btn-bordered btn-sm"><i class="fa fa-refresh"></i> <font>重置</font></a>
						<a id="easySearch" class="btn btn-success btn-bordered btn-sm" style="display: none;"><i class="fa fa-backward"></i> <font>返回</font></a>
						<a id="hardSearch" class="btn btn-success btn-bordered btn-sm" style="display: inline-block;"><i class="fa fa-search-plus"></i> <font>高级查询</font></a>
					</div>
				</div>
				<form id="editTableForm">
					<table id="table-list"></table>
				</form>
			</div>
		</div>
	</div>
</div>

<script>
    layui.use(['common', 'view', 'admin', 'laytpl'], function () {
        var $ = layui.$
            , R = layui.common
            , view = layui.view
            , admin = layui.admin
            , laytpl = layui.laytpl;

        var getTime = "-" + new Date().getTime();
        $("#body-div").attr("id", "body-div" + getTime);
        $("#table-list").attr("id","table-list" + getTime);
        var btnsStr = LayerUtil.getBtnsStrFromMenuData();
		var bootstrapTableUtil = new BootstrapTableUtil(getTime);
		bootstrapTableUtil.init({
			url: admin.basePath + '/dynamic/zform/data?path=path&traceFlag=&formNo=' + 'demo_righttable',
			method: 'post',
			columns: [
                {
					checkbox: true
				},
				{
					field: 'parent.name',
					title: '所属分类',
					sortable: true,
					sortName: 'a.parent_id',
					
					formatter:function(value, row , index){
						if(row.parent){
							return "<a href='javascript:;' class='view'>" + row.parent.name + "</a>";
						}else{
							return "";
						}
					},
					events: {
						'click .view': function (e, value, row, index) {
							viewForm({
								id: row.id
								,hashKey: row.hashKey
							})
						}
					},
				},
				{
					field: 's01',
					title: '名称',
					sortable: true,
					sortName: 'a.name',
					
				},
				{
					field: 'area01.name',
					title: '行政区',
					sortable: true,
					sortName: 'a.administrative',
					
				},
				{
					field: 'd01',
					title: '注册日期',
					sortable: true,
					sortName: 'a.date_of_registration',
					
					formatter:function(value, row, index){
						return (typeof value == "undefined" || value == null || value == "") ? "" : moment(value).format('yyyy-MM-dd'.replace(/yy/g,"YY").replace(/dd/g,"DD"));
					},
				},
                {
                	title: layui.admin.lang() ? 'Operation' : '操作',
                	width: '45px',
					"class": 'center must',
					events: {
						'click .view': function (e, value, row, index) {
							viewForm({id: row.id,hashKey: row.hashKey})
						},
						'click .edit': function (e, value, row, index) {
							addOrEdit({
								id: row.id
								,hashKey: row.hashKey
							})
						},
						'click .del': function (e, value, row, index) {
							delFuc(row);
						}
					},
					formatter: function(value, row, index) {
						return btnsStr.tableBtnsStr;
					},
                },
            ]
		},"demo_righttable");


		$("#body-div"+getTime).find("#addBtn").on("click",function(){
			addOrEdit({});
		});
		$("#body-div"+getTime).find("#importBtn").on("click",function(){
			LayerUtil.openDialog({
				title: '导入',
				formLay : 'demo_righttable',
				height:"300px",
				setDataWithoutAjax : true,
				url: 'admin/import',
	            btn: ['上传', '关闭'],
	            btn_EN: ['import', 'close'],
	            loading: false,
	            func1:function(index,layero){
					var validateForm = $(layero).find("#inputForm").validate({});
	            	if(validateForm.form()){
						var data = myHelper.composeData($(layero).find("#inputForm"));
						LayerUtil.ajax({
							url : admin.basePath + '/dynamic/zform/impdata?parentFormNo=&uniqueId=&toCompany=&parentId=&formNo=demo_righttable'+'&fileId='+data.importExcel+'&loginName='+localStorage.getItem('bpmUser'),
							type : 'post',
							shade: true,
							success : function(res) {
								LayerUtil.success(res[LayerUtil.getMsgLang()]);
								bootstrapTableUtil.refresh();
								layui.layer.close(index);
							}
						});
	            	}
	            }
			})
		});
		$("#body-div"+getTime).find("#exportBtn").on("click",function(){
			var str = $("#body-div"+getTime).find("#searchForm").serialize();
			var dataH = myHelper.formParamsToObject(str);
			window.open(admin.basePath + '/dynamic/zform/expdata?path=path&traceFlag=&formNo=demo_righttable&parentId=&zformString=' + encodeURI(JSON.stringify(dataH)));
			return;
		});

		$("#body-div"+getTime).find("#removeBtn").on("click",function(){
			var ids = bootstrapTableUtil.getMultiId();
			if(ids){
				LayerUtil.confirm(layui.admin.lang() ? "Are you sure?" : "确定删除吗？", function(){
					LayerUtil.ajax({
						type: 'post',
		        		url: admin.basePath + '/dynamic/zform/delete?formNo=demo_righttable&ids=' + ids,
		        		success: function(res){
		        			LayerUtil.success(res[LayerUtil.getMsgLang()]);
		        			bootstrapTableUtil.refresh();
		        		}
		        	})
				})
	       	}
		});

		function addOrEdit(initData) {
			var id = initData ? initData.id : '';
			if($("#body-div"+getTime).find('#treeId').val() && !id){
				initData.parent = {
					id: $("#body-div"+getTime).find('#treeId').val(),
					name: $("#body-div"+getTime).find('#treeName').val(),
				}
			}
			LayerUtil.openDialog({
				title : layui.admin.lang() ? 'New ' : '添加左树右表演示',
				formLay : 'demo_righttable',
				initData : initData,
				setDataWidthAjax : true,
				actionDataName : 'data',
				url : 'admin/demo_righttable/form',
				actionUrl : admin.basePath + '/dynamic/zform/getZform?formNo=demo_righttable&id=' + id,
	            btn : ['保存', '取消'],
	            btn_EN : ['Save', 'Cancel'],
	            func1 : function(index,layero) {
					var data = myHelper.composeData($(layero).find("#inputForm"));
	            	LayerUtil.ajax({
                		url : admin.basePath + '/dynamic/zform/save',
                		type : 'post',
                		data : JSON.stringify(data),
						shade: true,
                		success : function(res) {
                			LayerUtil.success(res[LayerUtil.getMsgLang()]);
                			bootstrapTableUtil.refresh();
                			layui.layer.close(index)
                		}
                	});
	            }
			})
		}

		function viewForm(initData) {
			LayerUtil.openDialogView({
				title : layui.admin.lang() ? 'View ' : '查看左树右表演示',
				formLay : 'demo_righttable',
				initData : initData,
				url : 'admin/demo_righttable/form',
				actionUrl : admin.basePath + '/dynamic/zform/getZform?formNo=demo_righttable&id=' + initData.id,
				actionDataName : 'data',
				setDataWidthAjax : true,
			})
		}

		function delFuc(row){
    		LayerUtil.confirm(layui.admin.lang() ? 'Are you sure you want to delete?':'确认要删除吗？', function() {
				LayerUtil.ajax({
					url: admin.basePath + '/dynamic/zform/delete?formNo=demo_righttable&ids=' + row.id,
					type:'post',
	        		shade:true,
					success: function(res){
	        			LayerUtil.success(res[LayerUtil.getMsgLang()]);
	        			bootstrapTableUtil.refresh();
	        		}
				});
			});
    	}

		//Left tree
		function refresh(node){
			$("#body-div"+getTime).find('#treeId').val(node.id);
			$("#body-div"+getTime).find('#treeName').val(node.text);
			bootstrapTableUtil.refresh();
			var html = layui.admin.lang() ? '/' : '左树右表演示/';
			$("#body-div"+getTime).find("#titleBar").html(html+node.text);
		}

		var jsTreeUtil = new JsTreeUtil(getTime,{
			url:admin.basePath + '/dynamic/zform/treeData?formNo=demo_tree&parentId&traceFlag=1',
			type: 'post',
			actionDataName: "data"
		});
		jsTreeUtil.init(refresh, layui.admin.lang() ? "All categories": "全部类型");

    });
</script>
